package com.zmn.oms.third.haobai.service.impl;

import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.entity.work.OrderWorkLogChange;
import com.zmn.oms.third.haobai.service.HaobaiService;
import com.zmn.oms.zmn.business.interfaces.open.OrderChangeNotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: huangyifeng
 * @description: 号百通知接口实现
 * @create: 2020-03-11 18:20
 **/
@Slf4j
@Service("haobaiNotifyService")
public class HaobaiNotifyServiceImpl implements OrderChangeNotifyService {

    @Autowired
    private HaobaiService haobaiService;

    @Override
    @SuppressWarnings("all")
    public void notifyChange(OrderWorkLogChange orderWorkLogChange) throws OmsBaseException {
        int logType = orderWorkLogChange.getLogType().intValue();

        try {
            // 完成(平台收款)
            if (OrderLogConsts.ORDER_LOG_TYPE_COMPLETE == logType) {
                haobaiService.notifyOrderStatus(orderWorkLogChange);
            }
            // 取消、失败、弃单
            else if (OrderLogConsts.ORDER_LOG_TYPE_CANCEL == logType ) {
                haobaiService.syncOrderCancel(orderWorkLogChange);
            }
        } catch (Exception e) {
            log.error(String.format("[号百] 同步异常：%s", e.getMessage()), e);
        }
    }
}
